/**
 * 添加或者修改页面
 */
var CategoryInfoDlg = {
    data: {
        id: "",
        name: "",
        createTime: "",
        createUser: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects','upload'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var upload = layui.upload;

    //普通图片上传
    var uploadInst=upload.render({
        elem: '#picBtn'
        , url: "/upload/upload"
        , before: function (obj) {
            layer.msg('文件上传中...', {
                icon: 16,
                shade: 0.01,
                time: 1000
            })
            setTimeout(function () {
                obj.preview(function (index, file, result) {
                    $('#cover').attr('src', result);
                });
            }, 2000)

        }
        , done: function (res) {
          if(res.stauts == 500) {
                layer.closeAll();
                Feng.error("上传失败！" + res.msg);
                //         return false;

            }else if(res.stauts==200) {
                setTimeout(function () {
                    $("#cover").val(res.url);
                    Feng.success(res.msg);
                }, 2000)
            }

        }
        , error: function () {
            Feng.error("上传图片失败！");
        }
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/category/addItem", function (data) {
            Feng.success("添加成功！");
            window.location.href = Feng.ctxPath + '/category'
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });

    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/category'
    });

});